package com.xzy.c;

import com.xzy.service.BookService;
import com.xzy.service.CourseService;
import com.xzy.service.SchoolService;
import com.xzy.service.TeacherService;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

/**
 * 依赖注入的方式：<bean autowire="byName"/> + set方法
 *
 * @author xzy
 * @date 2021/12/6  22:35
 */
@Slf4j
@ToString
public class ByNameSetterServiceImpl {
    private BookService bookService;
    private CourseService courseService;
    private SchoolService schoolService;
    private TeacherService teacherService;

    public ByNameSetterServiceImpl() {
        log.info("实例化 => ByNameSetterServiceImpl()");
    }

    /*
     * byName + setter：
     *     1. 遍历Bean中所有的set方法
     *     2. 解析set方法的名称，获取需要注入的bean的beanName
     *     3. 尝试根据beanName从容器中寻找Bean。如果找不到Bean，放弃调用set方法；如果能够找到Bean，调用set方法完成依赖注入；
     */

    /**
     * beanName：bookService1
     *
     */
    public void setBookService1(BookService bookService) {
        this.bookService = bookService;
        log.info("依赖注入 --> setBookService1({})", bookService);
    }

    /**
     * beanName：courseService2
     *
     */
    public void setCourseService2(CourseService courseService) {
        this.courseService = courseService;
        log.info("依赖注入 --> setCourseService2({})", courseService);
    }

    /**
     * beanName：schoolService1
     *
     */
    public void setSchoolService1(SchoolService schoolService) {
        this.schoolService = schoolService;
        log.info("依赖注入 --> setSchoolService1({})", schoolService);
    }

    /**
     * beanName：teacherService2
     *
     */
    public void setTeacherService2(TeacherService teacherService) {
        this.teacherService = teacherService;
        log.info("依赖注入 --> setTeacherService2({})", teacherService);
    }

    /**
     * beanName：teacherService123
     *
     */
    public void setTeacherService123(TeacherService teacherService) {
        this.teacherService = teacherService;
        log.info("依赖注入 --> setTeacherService123({})",teacherService);
    }
}
